class Solution
{
public:
    char slowestKey(vector<int> &releaseTimes, string keysPressed)
    {
        int lastRelease = 0;
        char longestKey = 'a';
        int maxDuration = 0;
        int n = releaseTimes.size();
        for (int i = 0; i < n; ++i)
        {
            int duration = releaseTimes[i] - lastRelease;
            if (duration > maxDuration)
            {
                maxDuration = duration;
                longestKey = keysPressed[i];
            }
            else if (duration == maxDuration)
            {
                longestKey = max(longestKey, keysPressed[i]);
            }
            lastRelease = releaseTimes[i];
        }
        return longestKey;
    }
};